﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Activities;
using System.Activities.Expressions;

namespace Vision.Core.ActivityComponents.Converters
{
	public class InArgumentBoolConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value != null && (value as System.Activities.Presentation.Model.ModelItem).ItemType == typeof(InArgument<bool>))
			{
				Activity<bool> expression = ((value as System.Activities.Presentation.Model.ModelItem).Source.ComputedValue as InArgument<bool>).Expression;
				if (expression is Literal<bool>)
				{
					return ((Literal<bool>)expression).Value;
				}
			}

			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value is bool)
			{
				return new InArgument<bool>(new Literal<bool>((bool)value));
			}
			else
			{
				return null;
			}
		}
	}
}
